using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.physx
{
[System.Serializable]
public  class Material :   cfg.EditorReadWriter 
 {

    public float dynamicFriction ;
     public float staticFriction ;
     public float bounciness ;
     public cfg.physx.ECombineMode frictionCombineMode ;
     public cfg.physx.ECombineMode bounceCombineMode ;
     


    public const int TYPE_ID = 2020387495;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(5);
        os.WriteSize(Tag.FLOAT | (1 << Tag.TAG_SHIFT));  os.WriteFloat(dynamicFriction);  
         os.WriteSize(Tag.FLOAT | (2 << Tag.TAG_SHIFT));  os.WriteFloat(staticFriction);  
         os.WriteSize(Tag.FLOAT | (3 << Tag.TAG_SHIFT));  os.WriteFloat(bounciness);  
         os.WriteSize(Tag.INT | (4 << Tag.TAG_SHIFT));  os.WriteInt((int)frictionCombineMode);  
         os.WriteSize(Tag.INT | (5 << Tag.TAG_SHIFT));  os.WriteInt((int)bounceCombineMode);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.FLOAT | (1 << Tag.TAG_SHIFT)):   dynamicFriction = os.ReadFloat(); break;  
             case (Tag.FLOAT | (2 << Tag.TAG_SHIFT)):   staticFriction = os.ReadFloat(); break;  
             case (Tag.FLOAT | (3 << Tag.TAG_SHIFT)):   bounciness = os.ReadFloat(); break;  
             case (Tag.INT | (4 << Tag.TAG_SHIFT)):   frictionCombineMode = (cfg.physx.ECombineMode)(os.ReadInt()); break;  
             case (Tag.INT | (5 << Tag.TAG_SHIFT)):   bounceCombineMode = (cfg.physx.ECombineMode)(os.ReadInt()); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Material");
        ele.WriteStartElement("dynamicFriction"); ele.WriteAttributeString("id", "1"); ele.WriteFloat(dynamicFriction); ele.WriteEndElement();
         ele.WriteStartElement("staticFriction"); ele.WriteAttributeString("id", "2"); ele.WriteFloat(staticFriction); ele.WriteEndElement();
         ele.WriteStartElement("bounciness"); ele.WriteAttributeString("id", "3"); ele.WriteFloat(bounciness); ele.WriteEndElement();
         ele.WriteStartElement("frictionCombineMode"); ele.WriteAttributeString("id", "4"); ele.WriteEnum(frictionCombineMode); ele.WriteEndElement();
         ele.WriteStartElement("bounceCombineMode"); ele.WriteAttributeString("id", "5"); ele.WriteEnum(bounceCombineMode); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  dynamicFriction = ele.ReadFloat(); break; 
                 case 2:  staticFriction = ele.ReadFloat(); break; 
                 case 3:  bounciness = ele.ReadFloat(); break; 
                 case 4:  frictionCombineMode = ele.ReadEnum<cfg.physx.ECombineMode>(); break; 
                 case 5:  bounceCombineMode = ele.ReadEnum<cfg.physx.ECombineMode>(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "dynamic_friction":  dynamicFriction = ele.ReadFloat(); break; 
                 case "static_friction":  staticFriction = ele.ReadFloat(); break; 
                 case "bounciness":  bounciness = ele.ReadFloat(); break; 
                 case "friction_combine_mode":  frictionCombineMode = ele.ReadEnum<cfg.physx.ECombineMode>(); break; 
                 case "bounce_combine_mode":  bounceCombineMode = ele.ReadEnum<cfg.physx.ECombineMode>(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
